home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Draggable ScriptX Folders / utils / widgets / label.sx < prev    next >
Encoding:
Text File  |  1995-12-06  |  2.1 KB  |  86 lines  |  [TEXT/ttxt]

  1. class Label ( TwoDPresenter)
  2. instance variables
  3.     frame:(new Frame)
  4.     _font
  5.     fill:(WhiteBrush)
  6.     textTransform:(MutableCopy IdentityMatrix)
  7.     textStencil
  8.     alignment:(@center)
  9.     autoResize:(true)
  10. end
  11. method init self { class Label }  #rest args #key        \
  12.             boundary:                                    \
  13.             text:("untitled")                            \
  14.             font:(theSystemFont)                        \
  15.             ->
  16. (
  17.     
  18.     if (not (isAKindOf text String)) do
  19.         text := text as String
  20.     local tStencil := new TextStencil font:font.font \
  21.         size:font.fontSize string:text
  22.     if (boundary = unsupplied) do (
  23.         local borderSpan := 6
  24.         boundary := new Rect x2:(tStencil.width+borderSpan) \
  25.             y2:(font.leading+borderSpan)
  26.     )
  27.     apply nextMethod self boundary:boundary stationary:true args
  28.     self.textStencil := tStencil
  29.     self._font := font
  30.     return self
  31. )
  32.  
  33. method recalcRegion self {class Label} ->
  34. (
  35.     local xOffset
  36.  
  37.     nextMethod self
  38.     SetBoundary self.frame self.boundary
  39.     local textTrans := self.textTransform
  40.     SetTo textTrans self.globalTransform
  41.     xOffset := case self.alignment of
  42.         @flushLeft    : 6
  43.         @center        : (self.boundary.width - self.textStencil.width)/2
  44.         @flushRight    : (self.boundary.width - self.textStencil.width - 6)
  45.         end
  46.     translate textTrans xOffset \
  47.         (self.boundary.y2 - (self._font.descent + 2))
  48. )
  49.     
  50. method draw self {class Label} surface clip -> 
  51. (
  52.     nextMethod self surface clip
  53.     Fill surface self.boundary clip self.globalTransform WhiteBrush
  54.     Fill surface self.textStencil clip self.textTransform BlackBrush                
  55.     drawLoweredFrame self.frame surface clip self.globalTransform
  56. )
  57.  
  58. method textGetter self {class Label} ->
  59. (
  60.     self.textStencil.string
  61. )
  62.  
  63. method textSetter self {class Label} newString->
  64. (
  65.     self.textStencil.string := newString as String
  66.     if (self.autoResize) then
  67.         self.width := self.textStencil.width + 8
  68.     else
  69.         notifyChanged self true
  70.     newString
  71. )
  72.  
  73. method fontGetter self {class Label} -> self._font
  74. method fontSetter self {class Label} newFont ->
  75. (
  76.     local tStencil := self.textStencil
  77.     tStencil.font := newFont.font
  78.     tStencil.size := newFont.fontSize
  79.     translate self.textTransform 0 (newFont.leading - self._font.leading)
  80.     if (self.autoResize) then
  81.         self.height := newFont.leading + 6
  82.     notifyChanged self true
  83.     self._font := newFont
  84. )
  85.  
  86.